﻿#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"

void test01()
{
	ST a;
	STInit(&a);
	STPush(&a, 1);
	STPush(&a, 2);
	STDateType i = STTop(&a);

	STPush(&a, 3);
	STPush(&a, 5);
	STPush(&a, 6);
	STPush(&a, 7);
	i = STTop(&a);

	STPush(&a, 8);

	STPop(&a);
	STPop(&a);
	STPop(&a);
	i = STTop(&a);

	STPop(&a);
	STPop(&a);

	i = STTop(&a);

	int j = STSize(&a);

	STDestroy(&a);
}

bool isValid(char* s) {
    ST pst;
    STInit(&pst);
    int i = 0;
    while (s[i] != '\0')
    {
        if (s[i] != ')' && s[i] != '}' && s[i] != ']')
        {
            STPush(&pst, s[i]);
        }
        i++;
    }

    i = 0;
    while (s[i] != '\0')
    {
        if (s[i] == ')' || s[i] == '}' || s[i] == ']')
        {
            char ret = STTop(&pst);
            STPop(&pst);
            if ((s[i] == ')' && (ret == '{' || ret == '[')) ||
                (s[i] == '}' && (ret == '(' || ret == '[')) ||
                (s[i] == ']' && (ret == '(' || ret == '{')))
            {
                return false;
            }
        }
        i++;
    }
    return true;
}

int main()
{
    char* s = "()[]{}";
    bool ret = isValid(s);

    printf("%d",ret);
	return 0;
}




